/* Usperspace program to retrieve PCI configuration details, Mac address and link status from the installed
 * Netowrk interface card(Intel 82578DC and Intel 82579V Gigabit Ethernet cards)
 * Instructions: 
 * 1.insmod chpciintf.ko and sudo ./makenode.sh
 * 2.Run the applicatin: sudo ./app
   3.Verfiy by dmesg 
 * Author : Lokesh V
 * Purpose : Assignment submission
 * Date: 06/11/2012
 * Version 0.1
*/

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <sys/ioctl.h>

int main ()
{
	int fd, rc;
    	char *nodename = "/dev/mycdrv";
    	unsigned char message[6]; 
    	char status;
	
    	printf ("MAC address and LINK Status for an installed PCI NIC card\n");
	fd = open (nodename, O_RDWR);
    	if (fd == -1) {
		perror ("open:");
		printf ("execute makenode.sh or insmod mycdev.ko\n");
		exit (0);
	}
	

	rc = read (fd, message, 6);
    	printf ("MAC Address %x:%x:%x:%x:%x:%x \n", message[0], message[1], message[2], message[3], message[4], message[5]);

    	rc = ioctl (fd,0, &status);
	if (rc == -1) {
		perror("ioctl:");
		exit (0);
	}

    	if (status)
		printf ("Link Status: Connected\n");
    	else 
    		printf ("Link Status: Disconnected\n");
    	close (fd);
    	exit (0);
}
